package com.example.servlet;

import com.example.dao.NovelDao;
import com.example.dao.UserDao;
import com.example.domain.Novel;
import com.example.domain.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;
@WebServlet("/AdminNovelDeleteServlet")
public class AdminNovelDeleteServlet extends HttpServlet{
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {
        request.setCharacterEncoding("utf-8");
        int novel_id=Integer.parseInt(request.getParameter("novel_id"));
        int page = Integer.parseInt(request.getParameter("page"));
        HttpSession session=request.getSession();
        NovelDao novelDao=new NovelDao();
        int result=novelDao.deleteNovelById(novel_id);
        if (result==1){
            request.setAttribute("msg","删除成功！");
        }else{
            request.setAttribute("msg","删除失败！");
        }
        List<Novel> novelList=novelDao.getNovelsByPage(page,10);
        if (novelList==null){
            request.setAttribute("msg","获取小说列表失败！");
        }
        session.setAttribute("novelList",novelList);
        request.getRequestDispatcher("admin_Novel.jsp").forward(request,response);
    }
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {
        doGet(request,response);
    }

}
